package com.example.plusz.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.example.plusz.entity.Clazz;
import com.example.plusz.entity.Student;
import com.example.plusz.service.ClazzService;
import com.mysql.cj.util.DnsSrv;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName ClazzController
 * @Description TODO
 * @Author HP
 * @Date 16:16 2022/7/21
 * @Version 1.0
 **/
@RestController
@RequestMapping("/clazz")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @RequestMapping("/findAll")
    private List<Clazz> findAll(){
        return clazzService.list(null);
    }

    @RequestMapping("/findById")
    private Clazz findById(@RequestParam Long cid){
            return clazzService.getById(cid);
    }
//    查询所有班级信息和对应学生信息
    @RequestMapping("/findStudentByClazz")
    private List<Clazz> findStudentByClazz(){
        return clazzService.findStudentByClazz();
    }

    @RequestMapping("/addClazz")
    private String addClazz(@RequestBody Clazz clazz){
        String str = new String();
        if (clazzService.save(clazz)){
            str = "添加成功";
            return str;
        }
        str = "添加失败";
        return str;
    }
    @RequestMapping("/updateClazz")
    private String updateClazz(@RequestBody Clazz clazz){
        String str = new String();
        if (clazzService.updateById(clazz)){
            str = "修改成功";
            return str;
        }
        str = "修改失败";
        return str;
    }
    @RequestMapping("/delClazz")
    private String delClazz(@RequestBody Long cid){
//        if (clazzService.getById(cid)==null){
//            return "班级不存在";
//        }
        String str = new String();
        if (clazzService.removeById(cid)){
            str = "删除成功";
            return str;
        }
        str = "删除失败";
        return str;
    }
    @RequestMapping("/delClazzByIds")
    private String delClazzByIds(@RequestBody List<Long> list){
        String str = new String();
        if (clazzService.removeByIds(list)){
            str = "删除成功";
            return str;
        }
        str = "删除失败";
        return str;
    }

}
